package com.ddwl.gate.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.gate.service.OperatorConfigService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.gate.OperatorConfigBo;
import com.ddwl.schema.bo.gate.OperatorConfigPageBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.gate.OperatorConfigVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author hemiaojun
 * @Date 2020/9/23 14:42
 */
@Api(tags = "运营商号段配置")
@RequestMapping("/mobile/operator")
@RestController
public class OperatorConfigController extends BaseController {

    @Resource
    private OperatorConfigService operatorConfigService;

    @PostMapping("/add")
    @ApiOperation("新增运营商号段")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo addConfig(@Valid @RequestBody OperatorConfigBo bo) {
        operatorConfigService.add(bo);
        return RestVo.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改运营商号段")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo update(@Valid @RequestBody OperatorConfigBo bo) {
        operatorConfigService.update(bo);
        return RestVo.ok();
    }

    @PostMapping("/delete")
    @ApiOperation("删除运营商号段")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo delete(@RequestParam("id") String id) {
        operatorConfigService.delete(id);
        return RestVo.ok();
    }

    @PostMapping("/page")
    @ApiOperation("后台获取运营商号段配置列表")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<PageVo<OperatorConfigVo>> configPage(@RequestBody PageBo<OperatorConfigPageBo> pageBo) {
        PageVo<OperatorConfigVo> pageVo=operatorConfigService.page(pageBo);
        return RestVo.ok(pageVo);
    }

    @PostMapping("/changeId")
    @ApiOperation("把id反转成时间戳")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeId(){
        operatorConfigService.changeId();
        return RestVo.ok();
    }


}
